<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class image extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
                       
	}
        
        private function add_activity_photo($act_id , $photoname){
            $sql = "INSERT  INTO  activity_photos VALUES(
                           NULL , 
                           '{$act_id}' , 
                           '{$photoname}'
                )";
            $this->db->query($sql);
            return  $this->db->insert_id();
        }
        
        public function remove(){
            if($_POST["id"]){
                $sql = "DELETE  FROM  activity_photos  WHERE activity_photos_id = '{$_POST[id]}'  ";
                $this->db->query($sql);
            }
        }


        public function upload_activity_images(){
                    
                    if(file_exists($_FILES["pho"]["tmp_name"])){
                         
                        $ext = explode(".",$_FILES["pho"]["name"]);
                        $file_type = "." . $ext[count($ext)-1];
                        $file_name =  md5(date("Y-m-d H:i:s")) . $file_type;
                        $path = "activity_photos/" .  $file_name;
                        if( @move_uploaded_file($_FILES["pho"]["tmp_name"], $path) ){
                            $id = $this->add_activity_photo($_POST["act_id"] , $file_name );
                             echo '<script>top.upload_callback({"id" : "' . $id  . '" , "location" : "' . base_url() . $path . "?rnd=" . md5(date("Y-m-d H:i:s")) . '"});</script>';
                        }
                    }   
                }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */